package com.itheima.day11.otherio.test2;

import java.io.*;

public class StudentDemo1 {
    public static void main(String[] args) {
        Student s1 = new Student("张三", 23);
        Student s2 = new Student("李四", 24);
        Student s3 = new Student("王五", 25);

        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream("backBurner\\Student.txt"));
            oos.writeObject(s1);
            oos.writeObject(s2);
            oos.writeObject(s3);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(oos != null){
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream("backBurner\\Student.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        while(true){
            try {
                Student stu = (Student) ois.readObject();
                System.out.println(stu);
            } catch (IOException e) {
                break;
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }



    }
}
